package com.leetcode;

import ds.TreeNode;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No101
 * @description
 * @date 2021/3/2 下午5:56
 */
public class No101 {
    public static void main(String[] args) {

    }

    public boolean isSymmetric(TreeNode root) {
        if(root == null){
            return true;
        }
        return isSubSymmetric(root.left,root.right);
    }

    private boolean isSubSymmetric(TreeNode left, TreeNode right){
        if(left == null && right == null){
            return true;
        }
        if(left == null || right == null){
            return false;
        }
        if(left.val != right.val){
            return false;
        }
        return isSubSymmetric(left.left,right.right) && isSubSymmetric(left.right,right.left);
    }

}
